package com.example.njupt.uis.mvp;

import com.example.njupt.base.BaseModel;
import com.example.njupt.base.mvp.BasePresenter;
import com.example.njupt.okhttp.entity.MusicEntity;
import com.example.njupt.okhttp.request.MusicRequest;
import com.example.njupt.okhttp.retrofit.ApiRetrofit;
import com.example.njupt.okhttp.retrofit.BaseObserver;
import com.example.njupt.okhttp.retrofit.RxSchedulers;

/**
 * Author:      mwang
 * Create Date: Created in 2021/4/26 11:43
 * Update Date:
 * Modified By:
 * Description:
 */
public class MvpPresenter extends BasePresenter<BaseModel, IMvpView> {

    @Override
    protected BaseModel createModel() {
        return new BaseModel();
    }

    void getMvp(String format) {
        MusicRequest request = new MusicRequest();
        request.setSongurl(format);
        ApiRetrofit.getInstance(getView()).getApiService().getMusic(format)
                .compose(RxSchedulers.applySchedulers(getLifecycleProvider()))
                .subscribe(new BaseObserver<MusicEntity>(getView()) {
                    @Override
                    protected void onError(String toString) {
                        getView().onError();
                    }

                    @Override
                    protected void onSuccess(MusicEntity result) {
                        getView().onSuccess(result);
                    }
                });
    }
}
